package com.tjsinfo.tjsoa.reminded.action;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tjsinfo.tjsoa.common.DayFormat;
import com.tjsinfo.tjsoa.common.DealString;
import com.tjsinfo.tjsoa.reminded.vo.TSystemReminded;
import com.tjsinfo.tjsoa.reminded.bo.TSystemRemindedManager;
import com.tjsinfo.tjsoa.system.vo.User;

public class RemindedViewAction extends Action {
	TSystemRemindedManager systemRemindedManager;
	
	
	public TSystemRemindedManager getSystemRemindedManager() {
		return systemRemindedManager;
	}


	public void setSystemRemindedManager(
			TSystemRemindedManager systemRemindedManager) {
		this.systemRemindedManager = systemRemindedManager;
	}


	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		try {
			String id=request.getParameter("id");
			HttpSession session=request.getSession();
			User user=(User)session.getAttribute("user");
			

//			TSystemRemindedManager tsfm=new TSystemRemindedManagerImpl();
			TSystemReminded tsf=systemRemindedManager.findById(Integer.valueOf(id));
			
			if(null == tsf){
				return mapping.findForward("failed");
			}else{
			String tag=request.getParameter("tag");
			Date date=new Date();
			if(tag==null){
			String readNameList=tsf.getReadNameList();
			readNameList=DealString.twoNoAgain(readNameList, readNameList+user.getUsername()+",");
			tsf.setReadNameList(readNameList);
			String memo=tsf.getMemo();
			if(!memo.contains(","+user.getUsername()+":")){
				memo=memo+user.getUsername()+":"+DayFormat.getFormatDate(date, DayFormat.Format24Datetime1)+",";
			}
			tsf.setMemo(memo);
			String readIdList=tsf.getReadIdList();
			readIdList=readIdList.replace(","+user.getUser_id()+",", ",");
			tsf.setReadIdList(readIdList);
			systemRemindedManager.update(tsf);
			}
			request.setAttribute("tsf", tsf);
			
			
			//右侧边栏
			//TMeetingNotifyManager tmnm=new TMeetingNotifyManagerImpl();
			//List<TMeetingNotify> tmnList=tmnm.findNoStart();
			//request.setAttribute("tmnList", tmnList);
			return mapping.findForward("success");
			}
		} catch (Exception e) {
			e.printStackTrace();

			return mapping.findForward("failed");
		}
	}
}
